package com.song.corebean.utils;

import java.net.InetSocketAddress;

import com.song.corebean.Host;
import com.song.corebean.MessageType;
import com.song.corebean.PackageHead;
import com.song.corebean.PackageMessage;

import io.netty.channel.ChannelHandlerContext;
public class CoreUtils {

	
	public static PackageMessage ctxToPackageMessage(ChannelHandlerContext ctx , MessageType messageType, String key , Object val)
	{
		PackageMessage msg = new PackageMessage();
		InetSocketAddress saddr = (InetSocketAddress)ctx.channel().remoteAddress();
		InetSocketAddress daddr = (InetSocketAddress)ctx.channel().localAddress();
		msg.head.setFromaddress(new Host(saddr.getAddress().toString(), saddr.getPort()));
		msg.head.setToaddress(new Host(saddr.getAddress().toString(), saddr.getPort()));
//		msg.head.todo=todo;
		msg.head.messageType = messageType;
		msg.body.bundle.put(key, val);
		
		return msg;
	}
	
	public static PackageMessage  dataToPackageMessage(MessageType messageType, String key , Object val)
	{
		PackageMessage msg = new PackageMessage();
//		msg.head.todo=todo;
		msg.head.messageType=messageType;
		msg.body.bundle.put(key, val);
		return msg;
	}
}
